﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Puzzles_IQ
{
    class TotalScore
    {
        public int Score { get; private set; }

        public TotalScore()
        {
            try
            {
                using (StreamReader sr = new StreamReader(@"Data\score.txt".AddApplicationPath()))
                {

                    string sc = sr.ReadLine();
                    Score = Convert.ToInt32(sc);
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                System.Windows.Forms.MessageBox.Show("Seems like score.txt file is absent in Data\\ folder. Creating a new one.");
                Score = 0;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message.ToString());
            }

        }

        public void AddScore(int s)
        {
            Score += s;
        }

        public void Save()
        {
            using (StreamWriter sw = new StreamWriter(@"Data\score.txt".AddApplicationPath()))
            {
                sw.WriteLine(Score.ToString());
            }

        }
    }
}
